package com.swu.pad.analysis.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpSession;

import org.ansj.splitWord.analysis.NlpAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huaban.analysis.jieba.JiebaSegmenter;
import com.swu.pad.analysis.service.AnalysisService;
import com.swu.pad.system.entity.User;
import com.swu.pad.util.PcsDictUtil;

@Controller
@RequestMapping(value = "/analysis")
public class AnalysisController {

	@Autowired
	private AnalysisService analysisService;
	
	/**
	 * 获取组内雷达图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getGroupRadar")
	public Map<String, Object> getGroupRadar(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getGroupRadar(activityId, user);
	}
	
	/**
	 * by    ZDB
	 * 获取    是否 给出组内互评建议结果       组内所有人 给自己打分完毕才允许前端  输出 建议     
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getGroupAdviceResult")
	public String getGroupAdviceResult(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getGroupAdviceResult(activityId,user);
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/getCourseRadar")
	public Map<String, Object> getCourseRadar(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getCourseRadar(activityId, user);//班级平均
	}

	

	/**
	 * 获取班级雷达图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getMutualCourseRadar")
	public Map<String, Object> getMutualCourseRadar(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getMutualCourseRadar(activityId, user);
	}
	
	
	
	/**
	 * 获取专注度折线图
	 * @param activityId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getFocusLine")
	public Map<String, Object> getFocusLine(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getFocusLine(activityId, user);
	}

	/**
	 * 获取组内字数饼图
	 * @param activityId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getGroupWordPie")
	public Map<String, Object> getGroupWordPie(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getGroupWordPie(activityId, user);
	}
	@ResponseBody
	@RequestMapping(value = "/getCourseWordPie")
	public Map<String, Object> getCourseWordPie(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getCourseWordPie(activityId, user);//班级平均
	}

	/**
	 * 获取组内版本数柱状图
	 * @param activityId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getGroupVersionBar")
	public Map<String, Object> getGroupVersionBar(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getGroupVersionBar(activityId, user);
	}
	@ResponseBody
	@RequestMapping(value = "/getCourseVersionBar")
	public Map<String, Object> getCourseVersionBar(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getCourseVersionBar(activityId, user);
	}

	/**
	 * 获取pad所有人专注度集合
	 * @param assignmentPadId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getFocus")
	public List getAverageFocusByMission(String activityId, HttpSession session) {
		User user = (User) session.getAttribute("user");
		return analysisService.getPadFocus(activityId, user.getId());
	}
	
	/**
	 * 获取组内社会网络图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getMutualtRelationship")
	public Map<String, Object> getMutualtRelationship(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getMutualtRelationship(activityId, user);
	}
	/**
	 * 获取组间雷达图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getGroupBetweenRadar")
	public Map<String, Object> getGroupBetweenRadar(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getGroupBetweenRadar(activityId, user);
	}
	/**
	 * 获取组间班级雷达图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getCourseBetweenRadar")
	public Map<String, Object> getCourseBetweenRadar(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getCourseBetweenRadar(activityId, user);
	}
	/**
	 * 获取班级社交网络图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getBetweenRelationship")
	public Map<String, Object> getBetweenRelationship(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getBetweenRelationship(activityId, user);
	}
	/**
	 * 获取组间社交网络图
	 * @param activityId
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/getBetweenRelationshipB")
	public Map<String, Object> getBetweenRelationshipB(String activityId, HttpSession session) throws Exception {
		User user = (User) session.getAttribute("user");
		return analysisService.getBetweenRelationshipB(activityId, user);
	}
	
	/**
	 * 获取文本分析所有相关内容
	 * @param padId
	 * @return
	 * @throws Exception 
	 * 默认最后一个版本  pad 内容
	 */
	@ResponseBody
	@RequestMapping(value = "/getTextAysContents")
	public Map<String,Object> getTextAysContents(String padId,String activityId,HttpSession session) throws Exception {
		JiebaSegmenter jbSeg = new JiebaSegmenter();
		Map<String,Object> resMap=new HashMap<String, Object>();
		User user = (User) session.getAttribute("user");
		//封装文本  和小组用户
		List<Map<String,Object>> userCutWords=new ArrayList<Map<String,Object>>();
		Map<String,String> allTexts=analysisService.getTextAysContents(padId, activityId,user);
		Set<String> keySet=allTexts.keySet();
		for (String key:keySet) {
			Map<String,Object> temMap=new HashMap<String, Object>();
			List<String> cutWord=jbSeg.sentenceProcess(allTexts.get(key));
			//String cutWord=ToAnalysis.parse(allTexts.get(key)).toStringWithOutNature();
			temMap.put(key,cutWord);
			userCutWords.add(temMap);
		}
		PcsDictUtil pcs=new PcsDictUtil();
		Map<String,Map<String,String>> maps=pcs.wordMap();
		resMap.put("dictRes", maps);
		resMap.put("userText",allTexts);
		resMap.put("cutTexts",userCutWords);
		return resMap;
	}
	

	
	
	
	
}
